package com.chrray.position.controller.web.sysUser;



import com.chrray.position.entity.position.SysUser;
import com.chrray.position.pojo.dto.auth.AllUserAddRequest;
import com.chrray.position.pojo.dto.auth.AllUserUpRequest;
import com.chrray.position.pojo.dto.auth.UserListDto;

import com.chrray.position.service.auth.MaSysUserService;
import com.chrray.position.service.auth.SysJurisdictionService;
import com.chrray.position.util.result.PageBean;
import com.chrray.position.util.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.chrray.position.util.result.ResponseResults.success;


/**
 * Created by IntelliJ IDEA.
 *
 * @Author: Q
 * @Created: 2021/1/12 19:54
 * @Description:
 * @Versions: 1.0
 */

@RestController

@RequestMapping("/api/web/user")
@Api(value  = "成员管理", tags  = "成员管理")
@Slf4j
@ResponseBody
public class SysUserController {

    @Resource
    private SysJurisdictionService sysJurisdictionService;

    @Resource
    private MaSysUserService iSysUserService;

    @ApiOperation(value =  "用户管理列表")
    @PostMapping(value = "/listUser")
    public ResponseResult<PageBean<SysUser>> listUser(@RequestBody UserListDto dto) {
        return iSysUserService.listUser(dto);
    }

    @GetMapping("/deleteUser")
    @ApiOperation(value =  "用户删除")
    public ResponseResult deleteUser(@RequestParam(value = "id") Long id) {
        return iSysUserService.deleteUser(id);
    }


    @ApiOperation(value =   "重置密码")
    @GetMapping(value = "/resettingPwd")
    public ResponseResult resettingPwd( @RequestParam(required = false) Long id) {
        return iSysUserService.resettingPwd(id);
    }

    @ApiOperation(value  = "编辑用户")
    @PostMapping(value = "/updateUser")
    public ResponseResult updateUser(@RequestBody AllUserAddRequest dto) {
        return iSysUserService.updateUser(dto);


    }

    @ApiOperation(value  = "添加用户")
    @PostMapping(value = "/addUser")
    public ResponseResult addUser(@RequestBody AllUserAddRequest dto) {
        return iSysUserService.addUser(dto);
    }


    @ApiOperation(value  = "启用。禁用")
    @PostMapping(value = "/upOrDownUser")
    public ResponseResult upOrDownUser(@RequestBody AllUserUpRequest sysUser) {
        return iSysUserService.upOrDownUser(sysUser);
    }

    @GetMapping("/selectById")
    @ApiOperation(value =  "查询成详情")
    public ResponseResult selectById( @RequestParam(value = "id") Long id) {
        return success(iSysUserService.selectById(id));
    }



}

